import re

str1 = "2018-07-13"

# 修改正则表达式，确保能匹配给定的字符串
result1 = re.search(r"(\d{4})-(\d{2})-(\d{2})", str1)
print("匹配后的结果对象为：", result1)

print(result1.group(),f"这不带参数，直接打印全部")
print(result1.group(1),f"取第一个数")
print(result1.group(2),f"取第二个值")
print(result1.group(3),f"取第三个值")
print(result1.groups(),f"以元组的形式展示")





str2 = "2018-07-13"

# 修改正则表达式，确保能匹配给定的字符串
result2 = re.search(r"^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})", str2)
print("匹配后的结果对象为：", result2)

if result2:  # 先判断是否匹配成功
    print(result2.group())
else:
    print("未匹配到结果")


pattern1 =re.compile(r"\d+")
pattern2 =re.compile(r"\w+",re.l)
